package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.battle.pojo.dto.role.UserRoleDto;
import com.battle.pojo.dto.warCaseStudy.WarCaseStudyUserDto;
import com.battle.pojo.entity.WarCaseStudyUser;
import com.battle.pojo.vo.warCaseStudyUser.GetWarCaseStudyUserListVo;
import com.battle.service.mapper.WarCaseStudyUserMapper;
import com.battle.service.repository.in.WarCaseStudyUserRepository;
import nirvana.core.repository.Repository;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
    import com.battle.pojo.dto.warCaseStudyUser.*;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.CollectionUtils;

/**
* 【描 述】：
* 【环 境】：J2SE
* 【详 细】：
*
*/
@Service
public class WarCaseStudyUserRepositoryImpl extends Repository< WarCaseStudyUserMapper , WarCaseStudyUser> implements WarCaseStudyUserRepository {

private final WarCaseStudyUserMapper mapper;

public WarCaseStudyUserRepositoryImpl(WarCaseStudyUserMapper mapper) {
this.mapper = mapper;
}

    /**
    * 搜索战例研讨用户
    * @param dto
    * @return
    */
    @Override
    public Page<GetWarCaseStudyUserListVo> selectWarCaseStudyUser(SelectWarCaseStudyUserDto dto){

    return mapper.selectWarCaseStudyUser(dto);
    }

@Override
public  Map<Long, WarCaseStudyUser> getMap(List<Long> ids){
    Map<Long, WarCaseStudyUser> map = new HashMap<>();

    if (CollectionUtil.isNotEmpty(ids)) {
        List<WarCaseStudyUser> list =listByIds(ids);
        if (CollectionUtil.isNotEmpty(list)) {
        map = list.stream().collect(Collectors.toMap(WarCaseStudyUser::getId, pojo -> pojo));
         }
        }
        return map;
    }


    @Override
    public Map<Long, List<WarCaseStudyUserDto>> getListByStudyIds(List<Long> studyIds) {
        if (CollectionUtils.isEmpty(studyIds)) {
            return Collections.EMPTY_MAP;
        }

        return mapper.getListByStudyIds(studyIds)
                .stream()
                .collect(Collectors.groupingBy(WarCaseStudyUserDto::getStudyId));
    }
}